﻿package 
{
    import flash.display.Sprite;

    public class Maze extends Sprite
    {
        private var m_rooms:Array = new Array();
        private var m_currRoom:Room = null;

        public function Maze() 
        {
            super();
        }

        public function addRoom(room:Room):void
        {
            m_rooms.push(room);
        }

        public function showRoom(number:uint):void
        {
            if (m_currRoom != null)
            {
                removeChild(m_currRoom);
            }

            m_currRoom = getRoomByNumber(number);
            m_currRoom.showRoom();

            if (m_currRoom == null)
            {
                throw ArgumentError("Incorrect room number");
            }

            addChild(m_currRoom);
        }


        public function getRoomByNumber(number:uint):Room
        {
            var room:Room = null;

            for (var i:uint = 0; i < m_rooms.length; ++i)
            {
                room = m_rooms[i];
                
                if (room.roomNumber == number)
                    break;
            }

            return room;
        }

        public function getCurrRoom():Room
        {
            return m_currRoom;
        }
    }
}
